﻿using DomainModel;
using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;

namespace Infrastructure.Mapper
{
    public class ArticleConfiguration: EntityTypeConfiguration<ArticleInfo>
    {
        public ArticleConfiguration()
        {
            // Primary Key
            this.HasKey(t => t.ContentId);

            // Properties
            this.Property(t => t.PartitionId)
                .IsRequired()
                .HasMaxLength(20);

            this.Property(t => t.Title)
                .HasMaxLength(100);

            this.Property(t => t.AdminUserName)
                .HasMaxLength(50);

            this.Property(t => t.ImgUrl)
                .HasMaxLength(100);

            // Table & Column Mappings
            this.ToTable("CTB_ArticleInfo");
            this.Property(t => t.ContentId).HasColumnName("ContentId");
            this.Property(t => t.PartitionId).HasColumnName("PartitionId");
            this.Property(t => t.CompanyID).HasColumnName("CompanyID");
            this.Property(t => t.Title).HasColumnName("Title");
            this.Property(t => t.AdminUserId).HasColumnName("AdminUserId");
            this.Property(t => t.AdminUserName).HasColumnName("AdminUserName");
            this.Property(t => t.ReleaseDate).HasColumnName("ReleaseDate");
            this.Property(t => t.ImgUrl).HasColumnName("ImgUrl");
            this.Property(t => t.Numbers).HasColumnName("Numbers").HasMaxLength(10);
            
            this.HasRequired(t => t.ArticleDetail)
             .WithRequiredPrincipal(t => t.Article)
             .WillCascadeOnDelete(true);

            //this.HasRequired(t => t.ArticleDetail)
            //   .WithRequiredPrincipal(t=>t.Article);

           // this.HasRequired(t => t.ArticleDetail).WithMany().HasForeignKey(t => t.ContentId);
        }
    }
}
